#include "proxy_local.h"

void SP_NPC_Spawner2 ( gentity_t *ent )
{
	if(ent->spawnflags & 256 && g_spskill->integer == 0)
	{
		//Not in Padawan
		return;
	}
	if(ent->spawnflags & 512 && g_spskill->integer == 1)
	{
		//Not in Jedi
		return;
	}
	if(ent->spawnflags & 1024 && g_spskill->integer == 2)
	{
		//Not in Jedi Knight
		return;
	}
	if(ent->spawnflags & 2048 && g_spskill->integer == 3)
	{
		//Not in Jedi Master
		return;
	}
	SP_NPC_Spawner(ent);
}

PatchData_t *SpawnHooks[149]; //yes you're not tripping...there's really 156 hooks involved here.
#define SPAWNHOOK_CALL(a, b, c)	SpawnHooks[a] = BG_PlacePatch(PATCH_CALL, b, ( unsigned int ) c)
#define SPAWNHOOK_JUMP(a, b, c)	SpawnHooks[a] = BG_PlacePatch(PATCH_JUMP, b, ( unsigned int ) c)

void PerformSpawnHooks( void )
{
	//Well, well. This is going to be absolutely AMAZING...
	//We need to do a total of 156 hooks in order to complete the difficulty bug fix.
	SP_NPC_Spawner = (SpawnFunc)DLLA(0x20042900, jagamex86);

	SPAWNHOOK_JUMP(0, DLLA(0x20042B32, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(1, DLLA(0x20042B5B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(2, DLLA(0x20042B6E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(3, DLLA(0x20042BB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(4, DLLA(0x20042B92, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(5, DLLA(0x20042BD2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(6, DLLA(0x20042BF2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(7, DLLA(0x20042C1D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(8, DLLA(0x20042C35, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(9, DLLA(0x20042C48, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(10, DLLA(0x20042C62, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(11, DLLA(0x20042C8D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(12, DLLA(0x20042CA5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(13, DLLA(0x20042CB8, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(14, DLLA(0x20042CDB, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(15, DLLA(0x20042CEE, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(16, DLLA(0x20042D12, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(17, DLLA(0x20042D32, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(18, DLLA(0x20042D52, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(19, DLLA(0x20042D72, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(20, DLLA(0x20042D92, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(21, DLLA(0x20042DB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(22, DLLA(0x20042DDB, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(23, DLLA(0x20042DEE, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(24, DLLA(0x20042E12, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(25, DLLA(0x20042E32, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(26, DLLA(0x20042E52, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(27, DLLA(0x20042F70, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(28, DLLA(0x20042F89, jagamex86), SP_NPC_Spawner2);

	SPAWNHOOK_CALL(28, DLLA(0x20043041, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(29, DLLA(0x20043056, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(30, DLLA(0x20043079, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(31, DLLA(0x2004308E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(32, DLLA(0x200430B2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(33, DLLA(0x200430DC, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(34, DLLA(0x2004311A, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(35, DLLA(0x20043138, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(36, DLLA(0x20043150, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(37, DLLA(0x20043168, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(38, DLLA(0x20043180, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(38, DLLA(0x20043193, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(39, DLLA(0x200431BA, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(40, DLLA(0x200431D3, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(41, DLLA(0x200431EC, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(42, DLLA(0x20043205, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(43, DLLA(0x20043228, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(44, DLLA(0x2004323D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(45, DLLA(0x20043282, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(46, DLLA(0x200432A2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(47, DLLA(0x200432D5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(48, DLLA(0x200432E8, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(49, DLLA(0x20043317, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(50, DLLA(0x2004332F, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(51, DLLA(0x20043342, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(52, DLLA(0x20043378, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(53, DLLA(0x2004338D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(54, DLLA(0x200433C5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(55, DLLA(0x200433D8, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(56, DLLA(0x20043404, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(57, DLLA(0x2004341D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(58, DLLA(0x20043440, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(59, DLLA(0x20043455, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(60, DLLA(0x20043485, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(61, DLLA(0x20043498, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(62, DLLA(0x200434D1, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(63, DLLA(0x200434E6, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(64, DLLA(0x200434FB, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(65, DLLA(0x20043510, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(66, DLLA(0x2004354C, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(67, DLLA(0x20043585, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(68, DLLA(0x20043598, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(69, DLLA(0x200435BC, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(70, DLLA(0x200435F5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(71, DLLA(0x20043608, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(72, DLLA(0x20043637, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(73, DLLA(0x2004364F, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(74, DLLA(0x20043662, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(75, DLLA(0x20043682, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(76, DLLA(0x200436B8, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(77, DLLA(0x200436CD, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(78, DLLA(0x20043707, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(79, DLLA(0x2004371F, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(80, DLLA(0x20043737, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(81, DLLA(0x2004374F, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(82, DLLA(0x20043762, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(83, DLLA(0x2004379E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(84, DLLA(0x200437B5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(85, DLLA(0x200437C8, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(86, DLLA(0x200437E3, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(87, DLLA(0x200437FA, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(88, DLLA(0x2004380D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(89, DLLA(0x20043824, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(90, DLLA(0x2004383B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(91, DLLA(0x2004384E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(92, DLLA(0x2004388E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(93, DLLA(0x200438A1, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(94, DLLA(0x200438BC, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(95, DLLA(0x200438CF, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(96, DLLA(0x200438E6, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(97, DLLA(0x200438F9, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(98, DLLA(0x2004392E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(99, DLLA(0x20043941, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(100, DLLA(0x2004395C, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(101, DLLA(0x2004396F, jagamex86), SP_NPC_Spawner2);

	SPAWNHOOK_JUMP(102, DLLA(0x20043986, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(103, DLLA(0x20043999, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(104, DLLA(0x20043A3B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(105, DLLA(0x20043A54, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(106, DLLA(0x20043A6D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(107, DLLA(0x20043A82, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(108, DLLA(0x20043AAC, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(109, DLLA(0x20043AD2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(110, DLLA(0x20043B08, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_CALL(111, DLLA(0x20043B1D, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(112, DLLA(0x20043B57, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(113, DLLA(0x20043B6F, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(114, DLLA(0x20043B87, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(115, DLLA(0x20043B9A, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(116, DLLA(0x20043BB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(117, DLLA(0x20043BD2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(118, DLLA(0x20043BF2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(119, DLLA(0x20043C1B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(120, DLLA(0x20043C2E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(121, DLLA(0x20043C52, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(122, DLLA(0x20043C72, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(123, DLLA(0x20043C92, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(124, DLLA(0x20043CB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(125, DLLA(0x20043CD2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(126, DLLA(0x20043CF2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(127, DLLA(0x20043D12, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(128, DLLA(0x20043D32, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(129, DLLA(0x20043D5B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(130, DLLA(0x20043D6E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(131, DLLA(0x20043D92, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(132, DLLA(0x20043DB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(133, DLLA(0x20043DD2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(134, DLLA(0x20043DF2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(135, DLLA(0x20043E12, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(136, DLLA(0x20043E32, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(137, DLLA(0x20043E52, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(138, DLLA(0x20043E72, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(139, DLLA(0x20043E92, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(140, DLLA(0x20043EB2, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(141, DLLA(0x20043EDB, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(142, DLLA(0x20043EEE, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(143, DLLA(0x20043F1B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(144, DLLA(0x20043F2E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(145, DLLA(0x20043F5B, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(146, DLLA(0x20043F6E, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(147, DLLA(0x20043F9C, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(148, DLLA(0x20043FD5, jagamex86), SP_NPC_Spawner2);
	SPAWNHOOK_JUMP(149, DLLA(0x20043FE8, jagamex86), SP_NPC_Spawner2);
}

void RemoveSpawnHooks( void )
{
	int i = 0;
	for(i = 0; i < 149; i++)
	{
		BG_RemovePatch(&SpawnHooks[i]);
	}
}